package com.qf.controller;

import com.qf.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/student")
@CrossOrigin // 允许跨域访问
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/reset")
    public HashMap<String,Object> reset(){
        System.out.println("请求进入了reset方法");
        HashMap<String, Object> result = new HashMap<>();
        // 调用 service层的对象完整具体的业务逻辑处理
        boolean flag = studentService.reset();
        if (flag){
            result.put("code",1);
            result.put("msg","ok");
        }else {
            result.put("code",-1);
            result.put("msg","error");
        }
        return result;
    }


    @GetMapping("/pick")
    public HashMap<String,Object> pick(){
        System.out.println("请求进入了pick方法");
        HashMap<String, Object> result = new HashMap<>();

        // 调用 service层的对象完整具体的业务逻辑处理
        String pickname = studentService.pickname();

        result.put("code",1);
        result.put("msg","ok");
        result.put("data",pickname);
        return result;

    }
}
